package com.emiage.ddutils;

import android.app.Activity;
import android.content.Intent;
import android.provider.Settings;
import android.text.TextUtils;

import java.io.Serializable;

/**
 * Created by LiJZ on 2016/7/22.
 */
public class ActivityUtils {
	/**
	 * 启动一个Activity并关闭当前Activity
	 *
	 * @param activity 当前Activity
	 * @param cls      要启动的Activity
	 */
	public static void startActivityAndFinish(Activity activity, Class<?> cls) {
		Intent intent = new Intent(activity, cls);
		activity.startActivity(intent);

		activity.finish();
	}

	/**
	 * 启动Activity
	 *
	 * @param activity 当前Activity
	 * @param cls      要启动的Activity Class
	 */
	public static void startActivity(Activity activity, Class<?> cls) {
		Intent intent = new Intent(activity, cls);
		activity.startActivity(intent);
	}

	/**
	 * 启动Activity并传int数据 key:"data"
	 *
	 * @param activity 当前Activity
	 * @param cls      要启动的Activity Class
	 * @param data     int型数据
	 */
	public static void startActivityForIntData(Activity activity, Class<?> cls, String dataName, int data) {
		Intent intent = new Intent(activity, cls);
		intent.putExtra(dataName, data);
		activity.startActivity(intent);
	}

	/**
	 * 启动Activity并传String数据 key:"data"
	 *
	 * @param activity 当前Activity
	 * @param cls      要启动的Activity Class
	 * @param data     String型数据
	 */
	public static void startActivityForStringData(Activity activity, Class<?> cls, String dataName, String data) {
		Intent intent = new Intent(activity, cls);
		intent.putExtra(dataName, data);
		activity.startActivity(intent);
	}

	/**
	 * 启动Activity传String数据并接收返回结果 key:"data"
	 *
	 * @param activity 当前Activity
	 * @param cls      要启动的Activity Class
	 * @param data     String型数据
	 * @param flag     int标记
	 */
	public static void startActivityForResult(Activity activity, Class<?> cls,String dataName, String data, int flag) {
		Intent intent = new Intent(activity, cls);
		if (TextUtils.isEmpty(dataName)) {
			intent.putExtra(dataName, data);
		}
		intent.setFlags(flag);
		activity.startActivityForResult(intent, flag);
	}

	/**
	 * 启动Activity并传序列化对象数据 key:"Serializable"
	 *
	 * @param activity 当前Activity
	 * @param cls      要启动的Activity Class
	 * @param data     String型数据
	 */
	public static void startActivityForSerializableData(Activity activity, Class<?> cls,String dataName, Serializable data) {
		Intent intent = new Intent(activity, cls);
		intent.putExtra(dataName, data);
		activity.startActivity(intent);
	}


	/**
	 * 启动网络设置
	 *
	 * @param activity 当前Activity
	 */
	public static void startSetNetActivity(Activity activity) {
		Intent intent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
		activity.startActivity(intent);
	}

	/**
	 * 启动系统设置
	 *
	 * @param activity 当前Activity
	 */
	public static void startSetActivity(Activity activity) {
		Intent intent = new Intent(Settings.ACTION_SETTINGS);
		activity.startActivity(intent);
	}
}
